From 122e5b3b0b8575e8c45967af9d7a1770e5d1ec99 Mon Sep 17 00:00:00 2001 From: Robert Lipe Date: Mon, 9 Dec 2019 11:30:31 -0600 Subject: [PATCH] Cleanup train keeps rollin' along defs.h: use c++ true and false. Replace macros with constexprs. gbser_win.cc don't use Windows style TRUE/FALSE. kml.cc: integration suggestions. msvc build: use units.h --- defs.h | 40 ++++++++++++++--------------------- gbser_win.cc | 22 +++++++++---------- kml.cc | 4 ++-- msvc/GPSBabel.vcxproj | 3 ++- msvc/GPSBabel.vcxproj.filters | 5 ++++- 5 files changed, 35 insertions(+), 39 deletions(-) diff --git a/defs.h b/defs.h index b80b26c7b..f8586083b 100644 --- a/defs.h +++ b/defs.h @@ -66,47 +66,39 @@ # define M_PI 3.14159265358979323846 #endif -#ifndef FALSE -# define FALSE false -#endif - -#ifndef TRUE -# define TRUE true -#endif - -#define FEET_TO_METERS(feetsies) ((feetsies) * 0.3048) -#define METERS_TO_FEET(meetsies) ((meetsies) * 3.2808399) +constexpr double FEET_TO_METERS(double feetsies) { return (feetsies) * 0.3048; }; +constexpr double METERS_TO_FEET(double meetsies) { return (meetsies) * 3.2808399; }; -#define NMILES_TO_METERS(a) ((a) * 1852.0) /* nautical miles */ -#define METERS_TO_NMILES(a) ((a) / 1852.0) +constexpr double NMILES_TO_METERS(double a) { return a * 1852.0;}; /* nautical miles */ +constexpr double METERS_TO_NMILES(double a) { return a / 1852.0;}; -#define MILES_TO_METERS(a) ((a) * 1609.344) -#define METERS_TO_MILES(a) ((a) / 1609.344) -#define FATHOMS_TO_METERS(a) ((a) * 1.8288) +constexpr double MILES_TO_METERS(double a) { return (a) * 1609.344;}; +constexpr double METERS_TO_MILES(double a) { return (a) / 1609.344;}; +constexpr double FATHOMS_TO_METERS(double a) { return (a) * 1.8288;}; -#define CELSIUS_TO_FAHRENHEIT(a) (((a) * 1.8) + 32) -#define FAHRENHEIT_TO_CELSIUS(a) (((a) - 32) / 1.8) +constexpr double CELSIUS_TO_FAHRENHEIT(double a) { return (((a) * 1.8) + 32);}; +constexpr double FAHRENHEIT_TO_CELSIUS(double a) { return (((a) - 32) / 1.8);}; -#define SECONDS_PER_HOUR (60L*60) -#define SECONDS_PER_DAY (24L*60*60) +constexpr double SECONDS_PER_HOUR = 60L * 60; +constexpr double SECONDS_PER_DAY = 24L * 60 * 60; /* meters/second to kilometers/hour */ -#define MPS_TO_KPH(a) ((a)*SECONDS_PER_HOUR/1000.0) +constexpr double MPS_TO_KPH(double a) { return (a)*SECONDS_PER_HOUR/1000.0;}; /* meters/second to miles/hour */ -#define MPS_TO_MPH(a) (METERS_TO_MILES(a) * SECONDS_PER_HOUR) +constexpr double MPS_TO_MPH(double a) { return METERS_TO_MILES(a) * SECONDS_PER_HOUR;}; /* meters/second to knots */ -#define MPS_TO_KNOTS(a) (MPS_TO_KPH((a)/1.852)) +constexpr double MPS_TO_KNOTS(double a) { return MPS_TO_KPH((a)/1.852);}; /* kilometers/hour to meters/second */ -#define KPH_TO_MPS(a) ((a)*1000.0/SECONDS_PER_HOUR) +constexpr double KPH_TO_MPS(double a) { return a * 1000.0/SECONDS_PER_HOUR;}; /* miles/hour to meters/second */ #define MPH_TO_MPS(a) (MILES_TO_METERS(a) / SECONDS_PER_HOUR) /* knots to meters/second */ -#define KNOTS_TO_MPS(a) (KPH_TO_MPS((a)*1.852)) +constexpr double KNOTS_TO_MPS(double a) {return KPH_TO_MPS(a) * 1.852; }; #define MILLI_TO_MICRO(t) ((t) * 1000) /* Milliseconds to Microseconds */ #define MICRO_TO_MILLI(t) ((t) / 1000) /* Microseconds to Milliseconds*/ diff --git a/gbser_win.cc b/gbser_win.cc index efb510d5c..66271cd9a 100644 --- a/gbser_win.cc +++ b/gbser_win.cc @@ -242,19 +242,19 @@ int gbser_set_port(void* handle, unsigned speed, unsigned bits, unsigned parity, GetCommState(h->comport, &tio); tio.BaudRate = mkspeed(speed); - tio.fBinary = TRUE; - tio.fParity = TRUE; - tio.fOutxCtsFlow = FALSE; - tio.fOutxDsrFlow = FALSE; + tio.fBinary = true; + tio.fParity = true; + tio.fOutxCtsFlow = false; + tio.fOutxDsrFlow = false; tio.fDtrControl = DTR_CONTROL_ENABLE; - tio.fDsrSensitivity = FALSE; - tio.fTXContinueOnXoff = TRUE; - tio.fOutX = FALSE; - tio.fInX = FALSE; - tio.fErrorChar = FALSE; - tio.fNull = FALSE; + tio.fDsrSensitivity = false; + tio.fTXContinueOnXoff = true; + tio.fOutX = false; + tio.fInX = false; + tio.fErrorChar = false; + tio.fNull = false; tio.fRtsControl = RTS_CONTROL_ENABLE; - tio.fAbortOnError = FALSE; + tio.fAbortOnError = false; tio.ByteSize = bits; tio.Parity = parity == 0 ? NOPARITY : (parity == 1 ? ODDPARITY : EVENPARITY); diff --git a/kml.cc b/kml.cc index e53e117cf..c45a31855 100644 --- a/kml.cc +++ b/kml.cc @@ -413,9 +413,9 @@ void trk_coord(xg_string args, const QXmlStreamAttributes*) } track_add_head(trk_head); - auto vecs = args.simplified().split(' '); + const auto vecs = args.simplified().split(' '); for(const auto& vec : vecs) { - QStringList coords = vec.split(','); + const QStringList coords = vec.split(','); auto csize = coords.size(); auto trkpt = new Waypoint; diff --git a/msvc/GPSBabel.vcxproj b/msvc/GPSBabel.vcxproj index 73717c53a..3888eaea7 100644 --- a/msvc/GPSBabel.vcxproj +++ b/msvc/GPSBabel.vcxproj @@ -412,6 +412,7 @@ + @@ -443,4 +444,4 @@ - \ No newline at end of file + diff --git a/msvc/GPSBabel.vcxproj.filters b/msvc/GPSBabel.vcxproj.filters index 8bf384f46..c999627df 100755 --- a/msvc/GPSBabel.vcxproj.filters +++ b/msvc/GPSBabel.vcxproj.filters @@ -848,6 +848,9 @@ Header Files + + Header Files + Header Files @@ -881,4 +884,4 @@ Generated Files - \ No newline at end of file + -- 2.30.2